﻿using UnityEngine;
using System.IO;
using System.Collections;

public class AssetLoader : Loader
{
	Object m_data = null;

	public AssetLoader()
		: base(Loader.LoaderType.ASSET)
	{

	}

	public override void Load()
	{
		base.Load();

#if UNITY_EDITOR
		System.Type type = m_param as System.Type;
		if (type == null)
		{
			type = typeof(Object);
		}

		if (m_async)
		{
			m_data = UnityEditor.AssetDatabase.LoadAssetAtPath(m_path, type);
		}
		else
		{
			Object data = UnityEditor.AssetDatabase.LoadAssetAtPath(m_path, type);
			OnLoadCompleted(data);
		}
#else
		if(!m_async)
		{
			OnLoadCompleted(null);
		}
#endif
	}

	public override void Update(float dt)
	{
		if (m_state == LoaderState.LOADING)
		{
			OnLoadCompleted(m_data);
			m_data = null;
		}
	}
}